
#ifndef XDNS_HOST_ENTRY_GENERATOR_H
#define XDNS_HOST_ENTRY_GENERATOR_H

#include "xdns.h"
#include <netinet/in.h>
#include <string>

class XdnsData;
class XdnsQuestionInfo;
class XdnsResourceRecordInfo;

class XdnsHostEntryGenerator
{
public:
    /*! Generate a host entry.

        This function uses the infos of request and response to generate a host
        entry. User needs to call delete to destroy the host entry until it is
        useless.

        @param requestedIpAddress The internet host address was used to request
                                  in the query.
        @param requestedHostname The hostname was used to request in the query.
        @param question The decoded info of DNS question section.
        @param resourceRecord The decoded info of DNS resource record.
        @param rawData The raw data of response.
        @param dataOffset The offset of data is used to specify where the base
                          postion of the DNS response is located.
        @param hostEntry On return the generated host entry. User needs to call
                         delete to destroy the host entry until it is useless.
        @return XE_Ok if success.
    */
    static XdnsError Generate(const struct in_addr* requestedIpAddress,
                              const std::string& requestedHostname,
                              const XdnsQuestionInfo& question,
                              const XdnsResourceRecordInfo& resourceRecord,
                              const XdnsData& rawData,
                              size_t dataOffset,
                              XdnsHostEntry** hostEntry);

private:
    XdnsHostEntryGenerator();
    ~XdnsHostEntryGenerator();

    static XdnsError GenerateForTypeA(const std::string& requestedHostname,
                                      const XdnsQuestionInfo& question,
                                      const XdnsResourceRecordInfo& resourceRecord,
                                      const XdnsData& rawData,
                                      XdnsHostEntry** hostEntry);
    static XdnsError GenerateForTypePtr(const struct in_addr* requestedIpAddress,
                                        const XdnsQuestionInfo& question,
                                        const XdnsResourceRecordInfo& resourceRecord,
                                        const XdnsData& rawData,
                                        size_t dataOffset,
                                        XdnsHostEntry** hostEntry);
};

#endif  // XDNS_HOST_ENTRY_GENERATOR_H

